/**
 * Copyright &copy; 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.chlitina.store.modules.sys.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.chlitina.store.common.persistence.BaseDao;
import com.chlitina.store.common.persistence.BaseDaoImpl;
import com.chlitina.store.modules.sys.entity.StoreMenu;

/**
 * 菜单DAO接口
 * @author ThinkGem
 * @version 2013-01-15
 */
public interface StoreMenuDao extends StoreMenuDaoCustom, CrudRepository<StoreMenu, Long> {

	@Modifying
	@Query("update StoreMenu set delFlag='" + StoreMenu.DEL_FLAG_DELETE + "' where id = ?1 or parentIds like ?2")
	public int deleteById(Long id, String likeParentIds);
	
	public List<StoreMenu> findByParentIdsLike(String parentIds);

	@Query("from StoreMenu where delFlag='" + StoreMenu.DEL_FLAG_NORMAL + "' order by sort")
	public List<StoreMenu> findAllList();
	
	@Query("select distinct m from StoreMenu m, StoreType r where m in elements (r.menuList) and r.id=?1" +
			" and m.delFlag='" + StoreMenu.DEL_FLAG_NORMAL + "' order by m.sort")
	public List<StoreMenu> findByStoreType(Long typeId);
	
	@Query("select distinct m from StoreMenu m, StoreType r where m in elements (r.menuList) and r.id=?1" +
			" and m.delFlag='" + StoreMenu.DEL_FLAG_NORMAL + "'")
	public List<StoreMenu> findValidByStoreType(Long typeId);
}

/**
 * DAO自定义接口
 * @author ThinkGem
 */
interface StoreMenuDaoCustom extends BaseDao<StoreMenu> {

}

/**
 * DAO自定义接口实现
 * @author ThinkGem
 */
@Repository
class StoreMenuDaoImpl extends BaseDaoImpl<StoreMenu> implements StoreMenuDaoCustom {
 
}
